﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin_Catalog_inc.aspx.cs" Inherits="newBlog.CenterInc.view_inc.admin.Admin_Catalog_inc" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>

<%@ Import Namespace="newBlog.CenterInc.tool" %>
<% 
    Response.ContentType = "application/json";
    if (Session["user_id"]==null) {
        Response.Write("{\"error\":\"您未登录本站\"}");
        return;
    }
    if (Convert.ToInt32(Session["user_grade"])!=1) { 
    Response.Write("{\"error\":\"您不是管理员\"}");
        return;
    }
    int mode = Request.Form["mode"] == null || Request.Form["mode"].Length == 0 ? 0 : Convert.ToInt32(Request.Form["mode"]);//1删除 2添加 3修改
    string catalog_id = Request.Form["catalog_id"] == null || Request.Form["catalog_id"].Length == 0 ? "" : Request.Form["catalog_id"];
    string catalog_name=Request.Form["catalog_name"] == null || Request.Form["catalog_name"].Length == 0 ? "" : Request.Form["catalog_name"];
    string catalog_content=Request.Form["catalog_content"] == null || Request.Form["catalog_content"].Length == 0 ? "" : Request.Form["catalog_content"];
    catalog_inc catalog_Inc = new catalog_inc();
    isString isString = new isString();
    switch (mode) {
        case 1:
            if (catalog_id.Length==0) {
                Response.Write("{\"error\":\"id不能为空\"}");
                return;
            }
            if (catalog_Inc.SelectCatalogArticle(catalog_id)) {
                Response.Write("{\"error\":\"当前分类内有文章请删除文章后在进行删除\"}");
                return;
            }
            if (catalog_Inc.DelCatalog(catalog_id)) {
                Response.Write("{\"error\":\"删除失败\"}");
                return;
            }

            Response.Write("{\"msg\":\"删除成功\"}");

            return;
        case 2:

            if (isString.isEmpty(catalog_name,catalog_content)) {
                Response.Write("{\"error\":\"禁止留空\"}");
                return;
            }
            if (catalog_Inc.AddCatalog(catalog_name,catalog_content)) {
                Response.Write("{\"error\":\"添加失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"添加成功\"}");
            return;
        case 3:
            if (isString.isEmpty(catalog_id,catalog_name,catalog_content)) {
                Response.Write("{\"error\":\"禁止留空\"}");
                return;
            }
            if (catalog_Inc.UpCatalog(catalog_id,catalog_name,catalog_content)) { 
            Response.Write("{\"error\":\"修改失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"修改成功\"}");
            return;
    }
    %>
